package org.wheel.plugins.toolkit.fieldrole;

import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.wheel.plugins.toolkit.sql.spi.FieldRoleSpi;

import java.util.List;

@AutoConfiguration
@EnableConfigurationProperties(FieldRoleProperties.class)
public class FieldRoleAutoConfiguration {

    /**
     * 刷新阶段再收集一次 SPI（含用户自定义 @Bean）
     */
    @Bean
    public FieldRoleRegistryBean fieldRoleRegistryBean(List<FieldRoleSpi> spiList) {
        return new FieldRoleRegistryBean(spiList);
    }

    @Bean
    @Order(0)   // 默认规则，可被用户覆盖
    public DefaultFieldRoleSpi defaultFieldRoleSpi(FieldRoleProperties properties) {
        return new DefaultFieldRoleSpi(properties);
    }
}